﻿using System;
using System.Collections.Generic;
using System.Web.Security;
using BUL;
using Entity;

namespace PM.Admin
{
    public partial class Login : System.Web.UI.Page
    {
        private UserBul bul = new UserBul();
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void btnDN_Click(object sender, EventArgs e)
        {
            string user = txtDN.Text;
            string pass = txtMk.Text;
            List<User> list = bul.User_Validate(user, pass);
            if (list.Count > 0)
            {
                FormsAuthentication.SetAuthCookie(user, false);
                Session["FullName"] = list[0].Name.Trim();
                Session["UserName"] = list[0].Username.Trim();
                Session["IsAdmin"] = list[0].Admin;
                Session["Id"] = list[0].Id;
                if (bul.User_Check_Login(user, pass))
                {
                    if (Session["HasLogin"] == null)
                    {
                        Session["HasLogin"] = user;
                        Response.Redirect("Admin.aspx");
                    }
                    else
                    {
                        Response.Redirect("Admin.aspx");
                    }
                }
            }
            else
            {
                Response.Redirect("Login.aspx");
                txtDN.Focus();
            }
           
        }
    }
}